package com.itheima.demo.controller;

import com.itheima.demo.bean.User;
import com.itheima.demo.repo.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserRepo userRepo;
    @RequestMapping("findAllUser")
    public List<User> findAllUser(){
        return userRepo.findAll();
    }
    @RequestMapping("addUser/{username}/{password}/{nickName}")
    public User addUser(@PathVariable String username,@PathVariable String password,@PathVariable String nickName){
        User user=new User();
        user.setId(10);
        user.setUsername(username);
        user.setPassword(password);
        user.setNickName(nickName);
        return userRepo.save(user);
    }
    @RequestMapping("/findUser/{username}")
    public User findUser(@PathVariable String username){
        return userRepo.findByUsername(username);
    }
    @RequestMapping("/byPassword/{password}")
    public List<User> findUserByPassword(@PathVariable String password){
        return userRepo.test01(password);
    }
}
